
import {
  getLeftTrees,
  addTreeNode,
  delTreeNode,
  editTreeNode,
  moveTreeNode,
  getReportList,
  checkCpasTableName,
  editCpasTableName,
  copyCpasTable,
  getCpasTableByTidsApi,
  // removeVerifyData,
  getAllVerifyData,
  removeDataAll,
  queryState,
  resetQueryState,
  queryVerifyState,
  templateExport,
  templateImport,
  batchFormula,
  templateExportExcel,
  isHaveTemplateDB,
  templateForNotesTreeList,
  alwaysShow,
  templateExportToSqlite,
  notesIsEmpty,
  reCalculateNotes,
  getAllVerifyTypeData,
  getNotesTreeZLToExportExcel,
  importExcelToColumnMatch,
  saveImportExcel,
  autoMathExcelToSystem,
  removeFormulaAll
} from "@/services/annotaionAnalysis";
// 附注 tab 页中左侧树 - 获取树节点列表
export async function getLeftTreeList(dbName: string, dataId: any) {
  const res = await getLeftTrees(dbName, dataId);
  if (res.ok) {
    return res.data;
  }
  return {};
}
// 新建树节点
export async function addTreeNodePage(params: any) {
  const res = await addTreeNode(params);
  if (res.ok) {
    return res;
  }
  return {};
}

// 删除树节点
export async function delTreeNodePage(id: string, dbName: string) {
  const res = await delTreeNode(id, dbName);
  if (res.ok) {
    return res;
  }
  return {};
}

// 调整树节点
export async function moveTreeNodePage(params: any, id: any) {
  const res = await moveTreeNode(params, id);
  if (res.ok) {
    return res;
  }
  return {};
}

//常在界面展示
export async function fetchAlwaysShow(params: any) {
  const res = await alwaysShow(params);
  if (res.ok) {
    return res;
  }
  return {};
}


// 修改节点 标题
export async function setEditTreeTittle(params: any) {
  const res = await editTreeNode(params);
  if (res.ok) {
    return res;
  }
  return {};
}

// 获取报表项目
export async function fetchReportList(params: any) {
  const res = await getReportList(params);
  if (res.ok) {
    return res;
  }
  return {};
}

// 检测 节点是否重名

export async function getCpasTableName(params: any) {
  const res = await checkCpasTableName(params)
  return res
}

// 修改cpas 表格名称

export async function editCpasTableNames(params: any) {
  const res = await editCpasTableName(params)
  return res
}

export async function copyCpasTableFun(params: any) {
  const res = await copyCpasTable(params)
  return res
}

// export async function removeVerifyDataFun(params: any) {
//   const res = await removeVerifyData(params)
//   return res
// }
// 勾稽汇总

export const getAllData = async (params: any) => {
  const res = await getAllVerifyData(params)
  return res
}

export const getAllTypeData = async (params: any) => {
  const res = await getAllVerifyTypeData(params)
  return res
}

export const clearDataAll = async (params: any) => {
  const res = await removeDataAll(params)
  return res
}
export const queryDataState = async (params: any) => {
  const res = await queryState(params)
  return res
}
export const queryResetState = async (params: any) => {
  const res = await resetQueryState(params)
  return res
}
export const queryVerifyStatezl = async (params: any) => {
  const res = await queryVerifyState(params)
  return res
}

export const menuTemplateExport = async (params: any) => {
  const res = await templateExport(params)
  return res
}

export const menuTemplateMerge = async (params: any) => {
  const res = await templateImport(params)
  return res
}

export const menuTemplateBatch =async (params: any) => {
  const res = await batchFormula(params)
  return res
}

export const menuTemplateExcel =async (params: any) => {
  const res = await templateExportExcel(params)
  return res
}

export const menuExportHaveTemplate =async (params: any) => {
  const res = await isHaveTemplateDB(params)
  return res
}

export const getTemplateForNotesTreeList = async (params: any) => {
  const res = await templateForNotesTreeList(params)
  return res
}

export const getTemplateExportToSqlite = async (params: any) => {
  const res = await templateExportToSqlite(params)
  return res
}
export const getNotesIsEmptyAPI = async (params: any) => {
  const res = await notesIsEmpty(params);
  return res
}

export const reCalculateNotesAPI = async (params: any) => {
  const res = await reCalculateNotes(params)
  return res
}

export const getNotesTreeZLToExportExcelAPI = async (params: any) => {
  const res = await getNotesTreeZLToExportExcel(params)
  const tempMsg = 'EBUSY: resource busy or locked, open';
  const tempMsg2 = 'ENOENT';
  const isTrue = res.msg.includes(tempMsg) || res.msg.includes(tempMsg2);
  if (isTrue) {
    return {
      code: res.code,
      msg: "文件已被程序打开，需要关闭已被打开的文件。",
      ok: res.ok,
      type: '导出'
    };
  }
  return res
}
export async function getCpasTableByTids(params: any) {
  const res = await getCpasTableByTidsApi(params)
  return res
}

export async function importExcelToColumnMatchAPI(params: any) {
  const res = await importExcelToColumnMatch(params)
  return res
}

export async function saveImportExcelAPI(params: any) {
  const res = await saveImportExcel(params)
  return res
}

export async function autoMathExcelToSystemAPI(params: any) {
  const res = await autoMathExcelToSystem(params)
  return res
}

/**
 * 批量清空公式 0510
 * @param params
 * @returns
 */
export const clearFormulaAPI = async (params: any) => {
  const res = await removeFormulaAll(params)
  return res
}
